/**
 * 
 */
package hanto.studentdlally.common;

import hanto.util.HantoCoordinate;

/**
 * @author Doug
 * @version 1
 *
 */
public class Coordinate implements HantoCoordinate {
	private final int x, y;
	
	/**
	 * @param x x coordinate
	 * @param y y coordinate
	 */
	public Coordinate(int x, int y){
		this.x = x;
		this.y = y;
	}
	
	/**
	 * Creates a Coordinate from a HantoCoordinate
	 * @param hc HantoCoordinate to convert to my coordinate type
	 * @return a new Coordinate witht the same x and y as the provided HantoCoordinate
	 */
	public static Coordinate generateCoordinate(HantoCoordinate hc){
		if(hc == null){
			return null;
		}
		return new Coordinate(hc.getX(), hc.getY());
	}
	
	/**
	 * Checks if a coordinate is adjacent to this coordinate
	 * @param c the coordinate to check
	 * @return true if adjacent, false otherwise
	 */
	public boolean isAdjacent(HantoCoordinate c){
		if(c == null){
			return false;
		}
		// Is c above this?
		if(c.getX() == x && c.getY() == y + 1){
			return true;
		}
		// Is c above and to the right?
		if(c.getX() == x + 1 && c.getY() == y){
			return true;
		}
		// Is c below and to the right?
		if(c.getX() == x + 1 && c.getY() == y - 1){
			return true;
		}
		// Is c below?
		if(c.getX() == x && c.getY() == y - 1){
			return true;
		}
		// Is c below and to the left?
		if(c.getX() == x - 1 && c.getY() == y){
			return true;
		}
		// Is c above and to the left?
		if(c.getX() == x - 1 && c.getY() == y + 1){
			return true;
		}
		// Otherwise, not adjacent
		return false;
	}

	/**
	 * @return the x
	 */
	public int getX() {
		return x;
	}

	/**
	 * @return the y
	 */
	public int getY() {
		return y;
	}

}
